import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28956
 * Date: 2024-07-17
 * Time: 17:31
 */
public class CardDemo {
    public static final String[] SUITS = {"♥","♣", "♦","♠"};
    //买牌
    public static List<Card> buyDeck(){
        List<Card> cardList = new ArrayList<>(52);
        //i代表每个数有4张牌，j代表13个数 52张牌没有大小王
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 13; j++) {
                String suit = SUITS[i];
                int rank = j;
                Card card = new Card();
                card.rank = rank;
                card.suit = suit;
                cardList.add(card);
            }

        }
        return cardList;
    }

    //洗牌
    public void shuffle(List<Card> cardList){
        Random random = new Random();
        //从最后一张牌开始往前交换
        for (int i = cardList.size()-1; i > 0; i--) {
            int index = random.nextInt(i);
            swap(cardList,i,index);
        }
    }
    public void swap(List<Card> cardList,int a,int b){
        Card tmp = cardList.get(a);
        cardList.set(a, cardList.get(b));
        cardList.set(b, tmp);
    }

    //揭牌
    //三个人每个人5张牌
    public void getCard(List<Card> cardList){
        List<Card> hand1 = new ArrayList<>();
        List<Card> hand2 = new ArrayList<>();
        List<Card> hand3 = new ArrayList<>();
        List<List<Card>> hands = new ArrayList<>();
        hands.add(hand1);
        hands.add(hand2);
        hands.add(hand3);

        //每三个人轮流抓5张牌，每次揭牌一张
        //i代表牌数，j代表人数
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                //每次从0下标开始揭牌
                Card card = cardList.remove(0);
                hands.get(j).add(card);
            }
        }
        System.out.println("第1个揭牌如下：");
        System.out.println(hand1);
        System.out.println("第2个揭牌如下：");
        System.out.println(hand2);
        System.out.println("第3个揭牌如下：");
        System.out.println(hand3);

        System.out.println("剩下的牌：");
        System.out.println(cardList);
    }
}
